package com.smh.controller;

import com.smh.model.UserInfo;
import com.smh.service.Impl.UserServiceImpl;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView show(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user/index.html");
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public String add(UserInfo userInfo){
        userService.add(userInfo);
        return "ok";
    }

    @ResponseBody
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public List<UserInfo> search(){
        return userService.search();
    }


}
